/*
 * testcase.cc
 *
 *  Created on: Jan 10, 2012
 *      Author: sihai
 */
#include "log4cpp.h"
#include "fixedsizerollingfilelogger.h"
#include "dailyrollingfilelogger.h"

#define BUFFER_SIZE 128

using namespace std;

int main(int argc, char** argv)
{
	char buffer[BUFFER_SIZE];
	memset(buffer, 0x00, BUFFER_SIZE);

	// FixedSizeRollingFileLogger
	Logger* logger = LoggerFactory::get_logger(FIXED_SIZE_ROLLING_FILE_LOGGER, 256,"/tmp/fixedsizerollingfilelogger.log", 128);
	if(logger == NULL)
	{
		return -1;
	}

	// debug
	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Debug Msg:%d", i);
		logger->log(DEBUG, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Info Msg:%d", i);
		logger->log(INFO, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Warn Msg:%d", i);
		logger->log(WARN, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Error Msg:%d", i);
		logger->log(ERROR, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Fatal Msg:%d", i);
		logger->log(FATAL, buffer);
	}
	delete logger;

	// DailyRollingFileLogger
	logger = LoggerFactory::get_logger(DAILY_ROLLING_FILE_LOGGER, 0,"/tmp/dailyrollingfilelogger.log");
	if(logger == NULL)
	{
		return -1;
	}

	// debug
	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Debug Msg:%d", i);
		logger->log(DEBUG, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Info Msg:%d", i);
		logger->log(INFO, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Warn Msg:%d", i);
		logger->log(WARN, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Error Msg:%d", i);
		logger->log(ERROR, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Fatal Msg:%d", i);
		logger->log(FATAL, buffer);
	}
	delete logger;


	// ConsoleLogger
	logger = LoggerFactory::get_logger(CONSOLE_LOGGER, 0);
	if(logger == NULL)
	{
		return -1;
	}

	// debug
	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Debug Msg:%d", i);
		logger->log(DEBUG, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Info Msg:%d", i);
		logger->log(INFO, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Warn Msg:%d", i);
		logger->log(WARN, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Error Msg:%d", i);
		logger->log(ERROR, buffer);
	}

	for(int i = 0; i < 100; i++)
	{
		snprintf(buffer, BUFFER_SIZE, "Test Fatal Msg:%d", i);
		logger->log(FATAL, buffer);
	}
	delete logger;
}


